home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 158_01 / qe3 < prev    next >
Text File  |  1987-10-10  |  6KB  |  305 lines

  1. /*  VERSION 0005  (DATE: 19/10/86)  (TIME: 13:37)  */
  2. /*
  3.     e (qe) screen editor
  4.  
  5.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  6.  
  7.     August-December 1981
  8.     Modified: To QE from e (ver 4.6a) by J.W. Haefner -- Oct 84-Mar 85
  9.  
  10.     FILE: qe3
  11.  
  12.     FUNCTIONS: putline,putoffset,putstatusline,putlineno,,putpage,
  13.             putmess,unmess,puts,rewrite,calcoffset,resetcursor
  14.  
  15.     PURPOSE: write text to screen
  16.  
  17. */
  18.  
  19. #include "qe.h"
  20.  
  21. putline(line,y)
  22. int line, y;
  23. {
  24.     char *getline(), *p, c;
  25.     int cp, bright, lastcol, off, x, nblank;
  26.  
  27.     deleteline(0,y);
  28.     if (line <= lastl) {
  29.  
  30. #if (SCRNDIMMD)                    /* highlight blocked lines */
  31.         bright= line == cline;
  32.         if (blocking && !bright) {
  33.             if (to) bright= (line >= from) && (line <= to);
  34.             else bright= (line >= (from > cline ? cline : from)) &&
  35.             (line <= (from > cline ? from  : cline));
  36.             }
  37. #else                            /* dim blocked lines if screen is brite */
  38.         bright = YES;
  39.         if (blocking) {        /* dim blocked lines */
  40.             if (to) bright= !( (line >= from) && (line <= to) );
  41.             else bright= !( (line >= (from > cline ? cline : from)) &&
  42.             (line <= (from > cline ? from  : cline)) );
  43.             }
  44. #endif
  45.         
  46.         lastcol=SWIDTH;
  47.         off=x=0;
  48.         p=getline(line);
  49.         if ( (line == cline && calcoffset()) || (blockscroll && offset) ) {
  50.             lastcol+=offset-1;
  51.             off=offset;
  52.             x=1;
  53.             makedim(); 
  54.             putch('<');
  55.             makebright();
  56.             }
  57.  
  58.         if (!bright) makedim();
  59.  
  60.         for (cp=nblank=0; *p && cp < lastcol; p++) {
  61.             if (*p == '\t')
  62.             do {
  63.                 if (cp >= off && cp < lastcol)
  64.                     /*putch(' ');*/
  65.                     nblank++;
  66.                 } 
  67.             while (++cp % tabwidth);
  68.             else {
  69.                 if (cp++ >= off) {        /*dispch(*p);*/
  70.                     if (*p == ' ') nblank++;
  71.                     else {
  72.                         if (nblank) {
  73.                             x+=nblank;
  74.                             if (nblank < GOTOLEN)
  75.                                 for (; nblank; nblank--)
  76.                                     bdos(DIRIO,' ');
  77.                             else {
  78.                                 gotoxy(x,y);
  79.                                 nblank=0;
  80.                                 }
  81.                             }
  82.                         dispch(*p);
  83.                         x++;
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.         if (*p && y < SHEIGHT) {
  89.             if (bright) makedim(); 
  90.             else makebright();
  91.             putch('>');
  92.             }
  93.         makebright();
  94.             /* check for input after each line put, save if there*/
  95.         if ( (c=bdos(DIRIO,0xff))) inbuf[inbufp++]=c & ~PARBIT;
  96.         }
  97. }
  98.  
  99. putoffset()
  100. {
  101.     int i;
  102.  
  103.     gotoxy(0,0);
  104.     if (offset) for(i=3-uspr(offset); i>0; i--) putch(' ');
  105.     else puts("   ");
  106.     gotoxy(0,cursory);
  107. }
  108.  
  109. putstatusline(line)
  110. int line;
  111. {
  112.     deleteline(FNPOS,0);
  113.     makedim();
  114.     puts(filename);
  115.     putlineno(line);
  116.     makebright();
  117.     if (errmess != NULL) {
  118.         gotoxy(EMPOS,0);
  119.         puts(errmess);
  120.         }
  121. }
  122.  
  123. putlineno(line)
  124. int line;
  125. {
  126.     int i;
  127.  
  128.     if (!displaypos) return;
  129.     gotoxy(LNPOS,0);
  130.     makedim();
  131.     i=uspr(line);
  132.     putch(':');
  133.     for (i=8-i-uspr(cursorx+1); i > 0; i--) putch(' ');
  134.     makebright();
  135. }
  136.  
  137. putpage()    /*display page more or less centered about 'cline'*/
  138. {
  139.     int y,line;
  140.     char c;
  141.  
  142.     pfirst= loc(cline,(topline-SHEIGHT)/2);
  143.     plast = loc(pfirst,SHEIGHT-topline);
  144.     putstatusline(cline);
  145.     for (line=pfirst, y=topline; line <= plast; line++, y++) {
  146.         if (cline == line) {
  147.             cursory = y;
  148.             cursorx = adjustc(cursorx);
  149.             }
  150.         putline(line,  y);
  151.         if (inbufp && (cline != 1) && (cline != lastl) )
  152.             if (((c=inbuf[0]) == tran[DOWNPAGE])
  153.                   || (c == tran[UPPAGE]) ) return;
  154.         }
  155.     if (y <= SHEIGHT) delpage(y);
  156. }
  157.  
  158. putmess(message)
  159. char *message;
  160. {
  161.     int lines;
  162.  
  163.         if (blankedmess && topline > blankedmess) {
  164.             gotoxy(3,blankedmess++);
  165.             puts(message);
  166.             return;
  167.         }
  168.  
  169.         if (topline == (helpon ? HELPLINES : 1)) lines=2;
  170.         else lines=1;
  171.         if (cursory <= (topline+=lines)) {
  172.              lines = cursory-(topline-lines);
  173.             cursory-=lines;
  174.             gotoxy(0,cursory);
  175.             for ( ; cursory < topline; cursory++) {
  176.                     insertline();
  177.                     if (plast != lastl) plast--;
  178.                 }
  179.             cursory+=lines;
  180.         }
  181.         else pfirst+= lines;
  182.         deleteline(0,topline-2);
  183.         deleteline(0,topline-1);
  184.         gotoxy(3,topline-2);
  185.         puts(message);
  186. }
  187.  
  188. xprtmess(message)        /*if an expert, short message of statusline*/
  189. char *message;
  190. {
  191.     deleteline(EMPOS,0);
  192.     puts(message);
  193.     blankedmess=NO;
  194. }
  195.  
  196. xmessoff()
  197. {
  198.     if (errmess==NULL) deleteline(EMPOS,0);
  199.     blankedmess=YES;
  200. }
  201.  
  202. unmess()
  203. {
  204.     int l, i, newtop, diff;
  205.  
  206.     newtop= (helpon ? HELPLINES : 1);
  207.     if (!(diff=topline-newtop)) return;
  208.     if (diff < PAGEOVERLAP && pfirst-diff < 1) {
  209.         if (blankedmess == newtop) return;
  210.         for (l=newtop; l < topline; l++) deleteline(0,l);
  211.         blankedmess=newtop;
  212.         return;
  213.     }
  214.     blankedmess=NO;
  215.     if ((pfirst-=diff) < 1) {
  216.         topline=newtop;
  217.         putpage();
  218.     }
  219.     else {
  220.         for (l=newtop, i=0; l < topline; l++, i++) putline(pfirst+i,l);
  221.         topline=newtop;
  222.     }
  223. }
  224.  
  225. puts(s)
  226. char *s;
  227. {
  228.     int dim;
  229.     char c;
  230.  
  231.     dim=NO;
  232.     while ( (c=*s++) )
  233.         switch(c) {
  234.         case BRIDIM :
  235.             (dim=!dim) ? begdim() : enddim(); 
  236.             break;
  237.         case '\n':    
  238.             putch('\r');
  239.         default  :    
  240.             putch(c);
  241.             }
  242.     if (dim) enddim();
  243. }
  244.  
  245. rewrite(cp,x)    /*rewrites current line from char 'cp', col 'x', onwards*/
  246. int cp, x;
  247. {
  248.     int i, begmark;
  249.     char cc,c;
  250.  
  251.     begmark= (calcoffset() > 0);
  252.     i= x-offset+begmark;
  253.     deleteline((i>0 ? i : 0),cursory);
  254.     if (!x && begmark) { 
  255.         begdim(); 
  256.         putch('<'); 
  257.         enddim(); 
  258.         }
  259.     while (x < SWIDTH+offset-begmark && (c=text[cp++])) {
  260.         if (c == '\t') {
  261.             for (i=tabwidth-x%tabwidth; i>0 && x<SWIDTH+offset-begmark; x++, i--)
  262.                 if (x >= offset) bdos(DIRIO,' ');
  263.             }
  264.         else if (x++ >= offset) {
  265.             dispch(c);
  266.             if (cc=bdos(DIRIO,0xff)) inbuf[inbufp++] = cc & ~PARBIT;
  267.             }
  268.         }
  269.     if (c && cursory < SHEIGHT) {
  270.         begdim(); 
  271.         putch('>'); 
  272.         enddim(); 
  273.         }
  274. }
  275.  
  276. calcoffset()
  277. {
  278.     /*for (offset=0; cursorx >= SWIDTH+offset-(offset>0); offset+=OFFWIDTH);*/
  279.     for (offset=(cursorx < lastoff ? 0 : lastoff);
  280.             cursorx >= SWIDTH+offset-(offset>0); offset+=OFFWIDTH);
  281.     return offset;
  282. }
  283.  
  284. resetcursor()
  285. {
  286.     int line, y;
  287.  
  288.     if (lastoff != calcoffset()) {
  289.         if (blockscroll) {
  290.             for (line=pfirst, y=topline; line <= plast; line++, y++)
  291.                 if (line != cline) putline(line,y);
  292.             }
  293.         putoffset();
  294.         rewrite(0,0);
  295.         lastoff=offset;
  296.         }
  297.     gotoxy(cursorx-offset+(offset>0),cursory);
  298. }
  299. ;
  300.     blankedmess=NO;
  301. }
  302.  
  303. xmessoff()
  304. {
  305.     if (errmess==NULL) deleteline(EMPOS,0);